package tp.pr3;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import tp.pr3.cityLoader.CityLoaderFromTxtFile;
import tp.pr3.util.ErrorMessages;
import tp.pr3.util.Messages;

public class Main {
	

	
	/**
	 * Inicializa los lugares y calles así como los parámetros para arrancar el robot
	 * @param args
	 * @throws IOException 
	 */
	public static void main (String args[]) {
		if (args.length == 0) {
			System.err.println(	Messages.BAD_PARAMS + Interpreter.LINE_SEPARATOR + 
								Messages.MAIN_USAGE_1 + Interpreter.LINE_SEPARATOR +  Interpreter.LINE_SEPARATOR + 
								Messages.MAIN_USAGE_2);
			System.exit(1);
		}
	
		City _places = null;		
		CityLoaderFromTxtFile loader = new CityLoaderFromTxtFile();
		
		//String path = "src/tp/pr3/cityLoader/cityFile";
		String path = args[0];
		FileInputStream iFS;
		try {
			iFS = new FileInputStream(path);
			try {
				_places = loader.loadCity(iFS);
			} catch (IOException e) {
				System.err.println(ErrorMessages.MAP_FILE_READING + args[0] + ErrorMessages.MAP_FILE_WRONG_SYNTAX );
				System.exit(2);
			}
		} catch (FileNotFoundException e1) {
			System.err.println(ErrorMessages.MAP_FILE_READING + args[0] + ErrorMessages.MAP_FILE_NO_EXIST );
			System.exit(2);
		}

		Direction direction = Direction.NORTH;		
		RobotEngine robotEngine = new RobotEngine( _places, loader.getInitialPlace(), direction);
		robotEngine.startEngine();
	}
	
	
	
}
